package com.maoatao.easycodegen.framework.model;

import lombok.Getter;

import java.util.Optional;

/**
 * PageRequest
 *
 * @author MaoAtao
 * @date 2025-10-04
 */
@Getter
public abstract class PageRequest extends ToString {

    public static final long DEFAULT_PAGE_SIZE = 10L;

    public static final long MAX_PAGE_SIZE = 1000L;

    private Long pageNo;

    private Long pageSize;

    public PageRequest() {
        this(1L, DEFAULT_PAGE_SIZE);
    }

    public PageRequest(Long pageNo, Long pageSize) {
        setPageNo(pageNo);
        setPageSize(pageSize);
    }

    protected void setPageNo(Long pageNo) {
        this.pageNo = Math.max(1, Optional.ofNullable(pageNo).orElse(1L));
    }

    protected void setPageSize(Long pageSize) {
        this.pageSize = Math.max(1, Math.min(Optional.ofNullable(pageSize).orElse(DEFAULT_PAGE_SIZE), MAX_PAGE_SIZE));
    }

}
